package com.utn.tp.integrador.notificaciones;

import com.utn.tp.integrador.R;
import com.utn.tp.integrador.activities.Main;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

public class NotificacionConexion {
	private static final int CONNECTION = 1;

	public static void notifyNetworkDisconnection(Context context) {

		String tickerText = context.getString(R.string.desconexion);

		Notification notification = new Notification(R.drawable.network,
				tickerText, System.currentTimeMillis());

		Intent intent = new Intent(context, Main.class);
		PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
				intent, 0);

		notification.setLatestEventInfo(context,
				context.getString(R.string.desconexion),
				context.getString(R.string.desconexion), pendingIntent);

		getManager(context).notify(CONNECTION, notification);
	}

	public static void notifyNetworkConnection(Context context, String t) {
		String tickerText = context.getString(R.string.conexion) + " " + t;

		Notification notification = new Notification(R.drawable.network,
				tickerText, System.currentTimeMillis());
		Intent intent = new Intent(context, Main.class);
		PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
				intent, 0);

		notification.setLatestEventInfo(context,
				context.getString(R.string.conexion) + " " + t,
				context.getString(R.string.conexion) + " " + t, pendingIntent);

		getManager(context).notify(CONNECTION, notification);
	}

	public static void cancelAll(Context context) {
		getManager(context).cancel(CONNECTION);
	}

	private static NotificationManager getManager(Context context) {

		NotificationManager mNotificationManager = (NotificationManager) context
				.getSystemService(Context.NOTIFICATION_SERVICE);
		return mNotificationManager;
	}

}
